jjzjj

javascript - 为每个模块组件重复模块名称

全部标签

ruby-on-rails - 如何在 RSpec 中包含多个模块?

我不确定将几个模块包含到RSpec中的方式,所以让我描述一下我的情况。在app/helpers下,我有两个带有助手的文件,包含模块ApplicationHelper和MailersHelper。尽管这些是我在我的View和邮件中使用的View助手,但我也在我的测试中使用了它们的一些方法,因此它们必须可以在describe子句中访问。在app/spec/mailers下,我还有一个文件,包含模块Helpers。该模块包含仅在测试中使用的方法(主要是长期期望的包装方法)。此外,我还有以下代码:classHelpersincludeSingletonincludeActionView::He

Ruby:从模块中将多个方法作为 proc 返回的更好方法

从模块中返回一个类似proc的方法非常容易:moduleFoodefself.bar#Methodimplementationenddefself.baz#Methodimplementationenddefself.qux#Methodimplemenatationenddefself.zoo#MethodimplementationendendFoo.method(:bar)#Returnsaprocobject但是如果我想从同一个模块返回多个(但不是全部)方法怎么办?一种方法是:[:bar,:baz].inject([]){|memo,i|memo有没有更好、更敏捷的方法来做同样

ruby - 什么标准证明在 Ruby 中使用模块而不是类?

我正在阅读我的ruby书。查看下面的代码,moduleDestroydefdestroy(anyObject)@anyObject=anyObjectputs"Iwilldestroytheobject:#{anyObject}"endendclassUserincludeDestroyattr_accessor:name,:emaildefinitialize(name,email)@name=name@email=emailendendmy_info=User.new("Bob","Bob@example.com")puts"Soyournameis:#{my_info.name}

ruby-on-rails - 如何在 Ruby 中封装包含的模块方法?

我希望能够在包含该模块的类无法访问的模块中拥有方法。给定以下示例:classFooincludeBardefdo_stuffcommon_method_nameendendmoduleBardefdo_stuffcommon_method_nameendprivatedefcommon_method_name#blahblahendend我希望Foo.new.do_stuff爆炸,因为它试图访问模块试图对其隐藏的方法。不过,在上面的代码中,Foo.new.do_stuff可以正常工作:(有没有办法在Ruby中实现我想做的事情?更新-真正的代码classPlace"Place"}has_

ruby - Watir-Webdriver 是否支持点击目标为 javascript 的链接?

我是Ruby和Watir-Webdriver的新手。我有一套用VBScript编写的站点自动化程序,我想将其转换为Ruby/Watir,因为我现在必须支持Firefox。我发现我真的很喜欢Ruby,而且我正在研究Watir,但我已经花了一周时间试图让Webdriver显示我的登录屏幕。该站点以带有“我同意”区域的“警告屏幕”开头。用户点击我同意并显示登录屏幕。我需要单击该区域以显示登录屏幕(这是同一页面,实际上是一个表单,只是隐藏了)。我整天都在用VBScript这样做:objExplorer.Document.GetElementsByTagName("area")(0).click

ruby-on-rails - Rails 4 ActionMailer around_action |访问操作信息(操作名称和参数)

我正在为我的customer_mailer类构建一个around_action,这样我就不必每次都在beginandrescue周围包装调用deliver_nowclassCustomerMaileremsg="Caughtexception!#{e}|#{action_name}"putsmsgraiseendend所以在救援中,我想记录消息,其中包含调用了哪个操作等信息,我设法找到方法action_name来显示调用了哪个操作,但我找不到检索传递给操作的参数的方法,有什么想法吗?谢谢! 最佳答案 在我回答你的问题之前:使用Bug

ruby-on-rails - ArgumentError(Api::V1 的副本已从模块树中删除但仍处于事件状态!)

这几天我一直在为这个问题苦苦挣扎。我有一个正在为其构建一些API的应用程序,并且上述错误总是在第一次运行时使我的应用程序崩溃。重新加载应用程序时错误消失,但仍然很烦人。以下是关于此错误的一些类似问题:AcopyofxxxhasbeenremovedfromthemoduletreebutisstillactiveArgumentError:AcopyofApplicationControllerhasbeenremovedfromthemoduletreebutisstillactive这两个链接都没有解决我面临的问题。这是完整的堆栈跟踪:ArgumentError(AcopyofAp

ruby - 你如何断言另一个 ruby​​ 模块的异常被抛出? (使用 assert_throws)

我正在尝试编写这样的代码:assert_throws(:ExtractionFailed){unit.extract_from('5x2005')}ExtractionFailed是Exception的一个简单子(monad)类,在test/unit下,我试图断言它在我调用unit.extract_from(...坏数据...)我已经将ExtractionFailed移动到SemanticText模块中,所以现在test/unit说:expectedtobethrownbutwasthrown.我尝试编写assert_throws(:SemanticText::ExtractionFa

ruby - 如何在命名空间类中包含模块?

我在将模块包含在命名空间类中时遇到问题。下面的示例抛出错误uninitializedconstantBar::Foo::Baz(NameError)。我在这里缺少哪些基本的Ruby知识?moduleFoomoduleBazdefhelloputs'hello'endendendmoduleBarclassFooincludeFoo::Bazendendfoo=Bar::Foo.new 最佳答案 使用::强制查找到顶层:moduleBarclassFooinclude::Foo::Bazendend

ruby-on-rails - "uninitialized constant"当包含测试助手模块时

我在尝试将辅助模块包含到测试中时遇到未初始化的常量错误。我的rails测试目录中有以下文件functional>admin>school_controller_test.rbfunctional>controller_helper.rb类/模块主体如下:moduleControllerHelperdefcheck_sort_order(items,column,direction)...endendclassAdmin::SchoolsControllerTest当我运行它时,测试输出是:/.../.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.3.